package com.logicalthinking.socialmall.service.impl;

import com.github.chenlijia1111.utils.common.Result;
import com.github.chenlijia1111.utils.core.PropertyCheckUtil;
import com.github.chenlijia1111.utils.core.StringUtils;
import com.github.chenlijia1111.utils.list.Sets;
import com.logicalthinking.socialmall.dao.ProductAppendMapper;
import com.logicalthinking.socialmall.entity.ProductAppend;
import com.logicalthinking.socialmall.service.ProductAppendServiceI;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * 产品附加属性
 *
 * @author chenLiJia
 * @since 2020-02-18 15:13:41
 **/
@Service
public class ProductAppendServiceImpl implements ProductAppendServiceI {


    @Resource
    private ProductAppendMapper productAppendMapper;


    /**
     * 添加
     *
     * @param params 添加参数
     * @return com.github.chenlijia1111.utils.common.Result
     * @author chenLiJia
     * @since 2020-02-18 15:13:41
     **/
    @Override
    public Result add(ProductAppend params) {

        int i = productAppendMapper.insertSelective(params);
        return i > 0 ? Result.success("操作成功") : Result.failure("操作失败");
    }

    /**
     * 编辑
     *
     * @param params 编辑参数
     * @return com.github.chenlijia1111.utils.common.Result
     * @author chenLiJia
     * @since 2020-02-18 15:13:41
     **/
    @Override
    public Result update(ProductAppend params) {

        int i = productAppendMapper.updateByPrimaryKeySelective(params);
        return i > 0 ? Result.success("操作成功") : Result.failure("操作失败");
    }

    /**
     * 根据产品id查询产品补充参数
     *
     * @param productId
     * @return
     */
    @Override
    public ProductAppend findByProductId(String productId) {
        if (StringUtils.isNotEmpty(productId)) {
            return productAppendMapper.selectByPrimaryKey(productId);
        }
        return null;
    }

    /**
     * 根据产品id集合查询出产品补充参数
     *
     * @param productIdSet
     * @return
     */
    @Override
    public List<ProductAppend> listByProductIdSet(Set<String> productIdSet) {
        if (Sets.isNotEmpty(productIdSet)) {
            return productAppendMapper.listByProductIdSet(productIdSet);
        }
        return null;
    }

    /**
     * 条件查询
     *
     * @param condition
     * @return
     * @author chenLiJia
     * @since 2020-02-18 15:13:41
     **/
    @Override
    public List<ProductAppend> listByCondition(ProductAppend condition) {

        PropertyCheckUtil.transferObjectNotNull(condition, true);
        return productAppendMapper.select(condition);
    }


}
